package cn.liu.hrm.web.controller;

import cn.liu.hrm.dto.SendSMSCodeDto;
import cn.liu.hrm.service.IVerifycodeService;
import cn.liu.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IVerifycodeService iVerifycodeService;

    //获取图片验证码
    @GetMapping("/imageCode/{imageCodeKey}")
    public String createImageCode(@PathVariable("imageCodeKey")String imageCodeKey){
        return iVerifycodeService.createImageCode(imageCodeKey);
    }

    //获取手机验证码
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody SendSMSCodeDto sendSMSCodeDto){
        try{
            iVerifycodeService.sendSmsCode(sendSMSCodeDto);
        }catch (RuntimeException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器异常"+e.getMessage());
        }
        return AjaxResult.me();
    }
}
